package android_testsuite.mytest.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import android.util.Log;

/**
 * @author Ren Hui
 * @since 1.0.1.058
 */
public class Executor {
    private int mPoolSizeMax = 1;
    private ExecutorService mThreadPoolExecutor;

    //构造函数
    public Executor(int poolSize) {
        super();
        this.mPoolSizeMax = poolSize;
        this.mThreadPoolExecutor = Executors.newFixedThreadPool(mPoolSizeMax);
    }

    /**
     * 传进来的参数是Runable线程
     *
     * @param runnable
     */
    public void start(Runnable runnable) {
        if(runnable != null) {
            this.mThreadPoolExecutor.execute(runnable);
        }
    }

    /**
     * 关闭线程池的方法
     */
    public void close() {
        if (!mThreadPoolExecutor.isShutdown()) {
            Log.d(null, "线程池关闭");
            mThreadPoolExecutor.shutdown();
        }
    }
}
